//Accepted
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

vector<int> v[1000];
queue<int> q;
int tem[1000];
int pass[2][1000];
bool pode[1000];
int k, n, m, i, j, x, y, sum, a, ll, kk;
int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	scanf("%d%d%d", &k, &n, &m);
	
	memset(tem,0,sizeof(tem));
	for(i=0;i<k;++i){
		scanf("%d", &x);
		tem[--x]++;
		j=x;
	}
	for(i=0;i<m;++i){
		scanf("%d%d", &x,&y);
		--x;--y;
		v[x].push_back(y);
	}
	sum=0;
	//for(i=0;i<n;++i){printf("%d : %d\n", i+1, tem[i]);for(j=0;j<k;++j){printf("%d ", pode[i][j]);}printf("%d\n");}
	
	memset(pass,0,sizeof(pass));
	memset(pode,1,sizeof(pode));
	for(i=0;i<n;++i)pass[0][i]=-1;
	
	for(ll= kk = 0;kk<n;++kk,j=(j+1)%n)
	{
		
		if(pode[j])
		{
			//printf("%d ==\n", j);
			
			a=tem[j];
			tem[j]=0;
			if(pass[!(ll&1)][j]+a>pass[(ll&1)][j])pass[ll&1][j]=pass[!(ll&1)][j]+a;
			
			
			q.push(j);
			if(pass[ll&1][j]==k)sum++;
			
			while(!q.empty()){
				x=q.front();q.pop();
				
				//printf("%d : %d, %d=%d\n", x, tem[x], a,pass[ll&1][x]);
				
				for(i=0;i<v[x].size();++i){
					y=v[x][i];
					pode[y]=0;
					a+=tem[y];
					tem[y]=0;
					if(pass[!(ll&1)][y]+a>pass[(ll&1)][y]){
						pass[ll&1][y]=pass[!(ll&1)][y]+a;
						if(pass[ll&1][y]==k)sum++;
						q.push(y);
					}
				}
			}
			++ll;
			for(i=0;i<n;++i)pass[ll&1][i]=pass[!(ll&1)][i];
		}
	}
	printf("%d\n", sum);
	
	return 0;
}
